/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
	"fmt"

	"gitee.com/lys_billy/bpf-map/pkg/bpf"
	"github.com/spf13/cobra"
)

// updateCmd represents the update command
var updateCmd = &cobra.Command{
	Use:   "update",
	Short: "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		mapname, _ := cmd.Flags().GetString("name")
		key, _ := cmd.Flags().GetUint32("key")
		value, _ := cmd.Flags().GetUint32("value")
		m := bpf.UpdateMap(mapname, key, value)
		if m == nil {
			fmt.Errorf("update map 错误")
		}
		fmt.Printf("update map  %s success !\n", mapname)
	},
}

func init() {
	rootCmd.AddCommand(updateCmd)

	// Here you will define your flags and configuration settings.
	updateCmd.Flags().StringP("name", "n", "cilium-test-map", "--name=test")
	updateCmd.Flags().Uint32P("key", "k", 0, "--key=0")
	updateCmd.Flags().Uint32P("value", "v", 0, "--value=0")
}
